package com.itc.bi.service.impl;

import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itc.bi.entity.functionConfigEntity;
import com.itc.bi.mapper.FunctionConfigMapper;
import com.itc.bi.service.FunctionConfigService;
import org.springframework.stereotype.Service;
import java.util.*;

/**
 * @author xuzy
 */
@Service
public class FunctionConfigServiceImpl extends ServiceImpl<FunctionConfigMapper, functionConfigEntity> implements FunctionConfigService {

    @Override
    public List<JSONObject> tree() {
        List<JSONObject> dataList = new ArrayList();
        Map<String,List<functionConfigEntity>> map = new LinkedHashMap<>();
        List<functionConfigEntity> list = list(Wrappers.lambdaQuery(functionConfigEntity.class).orderByAsc(functionConfigEntity::getSort));
        list.stream().forEach(item -> {
            if(!map.containsKey(item.getType())){
                map.put(item.getType(),new ArrayList<>());
            }
            map.get(item.getType()).add(item);
        });
        map.keySet().stream().forEach(type -> {
            JSONObject data = new JSONObject();
            data.put("label",map.get(type).get(0).getTypeLabel());
            data.put("child",map.get(type));
            dataList.add(data);
        });
        return dataList;
    }
}




